package com.itheima.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.BaseContext;
import com.itheima.common.R;
import com.itheima.domian.Orders;
import com.itheima.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    @PostMapping("submit")
    public R<String> submit(@RequestBody Orders orders) {
        ordersService.submit(orders);
        return R.success("下单成功");
    }

    //手机查询订单
    @GetMapping("userPage")
    public R<Page<Orders>> userPage(Integer page, Integer pageSize) {
        //分页查询
        Page<Orders> pages = new Page<>(page, pageSize);
        Page<Orders> page1 = ordersService.page(pages, Wrappers.<Orders>lambdaQuery().eq(Orders::getUserId, BaseContext.getId()));
        return R.success(page1);
    }

    //后端查询订单
    @GetMapping("page")
    public R<Page<Orders>> page(Integer page, Integer pageSize, Long number, String beginTime, String endTime) {
        Page<Orders> pages = ordersService.pages(page, pageSize, number, beginTime, endTime);
        return R.success(pages);
    }
}